/*
 * Copyright @ 2024 weili23
 * com.example.mythread.a07threadExerciseMovie 15:35
 * All right reserved.
 */

package com.example.mythread.a07threadExerciseMovie;

/**
 * @desc:
 * @author: weili23
 * @createTime: 2024/10/21 15:35
 * @version: v1.0
 */
public class Movie extends Thread{
    //初始化1000张票
    public static int ticketNum = 1000;
    @Override
    public void run() {
        while (true){
            synchronized (Movie.class){
                if(ticketNum == 0){
                    break;
                }else{
                    try {
                        Thread.sleep(30);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticketNum--;
                    System.out.println(Thread.currentThread().getName()+"领取了一张电影票，剩余电影票数量："+ticketNum);
                }
            }
        }
    }
}
